/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.hibernate.dao;

import com.cashmate.hibernate.pojo.Informants;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;

/**
 *
 * @author Sarah
 */
public class InformantsDAO extends DAO {

    public InformantsDAO() {
        super();
    }

   
    @SuppressWarnings("unchecked")
    public List<Informants> findByCriteria(DetachedCriteria dc, int from, int size) throws Exception {
        Criteria criteria = dc.getExecutableCriteria(getSession());
        criteria.setFirstResult(from);
        criteria.setMaxResults(size);
        criteria.setCacheable(true);
        List<Informants> list = criteria.list();
        flush();
        return list;
    }

    @SuppressWarnings("unchecked")
    public int countByCriteria(DetachedCriteria dc) throws Exception {
        Criteria criteria = dc.getExecutableCriteria(getSession());
        criteria.setCacheable(true);
        criteria.setProjection(Projections.rowCount());
        int count = ((Integer) criteria.list().get(0)).intValue();
        flush();
        return count;
    }
}
